package com.meta.menu.controller;


import com.meta.common.CommonInfo;
import com.meta.menu.bo.Menu;
import com.meta.menu.bo.RouteMenu;
import com.meta.menu.service.MenuService;
import com.meta.menu.service.UserMenuService;
import com.meta.nd.vo.RequestMessage;
import com.meta.nd.vo.ReturnMessage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/menu", produces = "application/json")
public class MenuController {
	
	@Resource
	MenuService menuService;
	@Resource
	UserMenuService userMenuService;

	@RequestMapping(value = "/getRootMenu", method = { RequestMethod.POST })
	public ReturnMessage<Menu> getRootMenu(@RequestBody RequestMessage<String> requestMessage) {
		Menu rootMenu = this.menuService.getRootMenu("1");
		return new ReturnMessage<Menu>(rootMenu,true);
	}

	@RequestMapping(value = "/getRouteMenu", method = { RequestMethod.POST })
	public ReturnMessage<RouteMenu> getRouteMenu(@RequestBody RequestMessage<String> requestMessage) {
		CommonInfo commonInfo = requestMessage.getCommonInfo();
		String userCode = commonInfo.getUserCode();
		RouteMenu rootMenu = this.userMenuService.getRouteMenu(userCode);
		return new ReturnMessage<RouteMenu>(rootMenu,true);
	}
}
